package cn.chencaiju.day01;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

public class DruifTest {
	DruidDataSource ds;
	
	@Before public void initlized() throws IOException {
		ds=new DruidDataSource();
		Properties prop=new Properties();
		InputStream is=getClass().getClassLoader()
				.getResourceAsStream("druid.properties");
		prop.load(is);
		ds.configFromPropety(prop);
	}
	
	@Test public void testDruid() throws SQLException {
		DruidPooledConnection connection = ds.getConnection();
		PreparedStatement ps = connection.prepareStatement("select * from student");
		ResultSet set = ps.executeQuery();
		while(set.next()) {
			System.out.println(set.getInt(1)+"\t"+set.getString(2));
		}
	}
	
	@After public void clear() {
		
	}
}
